package grafica;

import java.awt.Graphics;
import java.awt.MediaTracker;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JPanel;
import java.awt.Toolkit;

public class EndPanel extends JPanel implements KeyListener {

	MediaTracker mt;
	Toolkit t;
	Myframe mf;
	
	public EndPanel(Myframe mf)  {
		super();
		this.setFocusable(true);
		this.addKeyListener(this);
		
		t= Toolkit.getDefaultToolkit();
		mt = new MediaTracker(this);
		mt.addImage(t.getImage("images/Menu/Vittoria/VittoriaPanel.png"),0);
		mt.addImage(t.getImage("images/Menu/menu.png"), 1);
		mt.addImage(t.getImage("images/Menu/Esci.png"), 2);
		mt.addImage(t.getImage("images/Menu/classificaButton.png"), 3);
		
		this.mf = mf;
		this.requestFocus();
		
		try {
			mt.waitForAll();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void paintComponent(Graphics g) {
		g.fillRect(0, 0, Myframe.SCREEN_WIDTH, Myframe.SCREEN_HEIGHT);
		g.drawImage(t.getImage("images/Menu/Vittoria/VittoriaPanel.png"), 0, 0, null);
		g.drawImage(t.getImage("images/Menu/menu.png"), 450, 300, null);
		g.drawImage(t.getImage("images/Menu/Esci.png"), 460, 400, null);
		g.drawImage(t.getImage("images/Menu/classificaButton.png"),440,500,null);
	}

	public void keyPressed(KeyEvent e) {
		if (e.getKeyCode() == KeyEvent.VK_SPACE) {
			mf.menu();		
		}
		else if (e.getKeyCode() == KeyEvent.VK_Q) {
			System.exit(0);
		}
		else if (e.getKeyCode() == KeyEvent.VK_C){
			mf.classificaPanel();
		}
	}

	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
}